﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for clsDOTTHU
/// </summary>
public class clsDOTTHU
{
    public clsDOTTHU()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    #region Properties
    #region Get So Tien Thu
    public static decimal GetMoney(DataTable dt)
    {
        decimal money = 0;
        if (dt.Rows.Count > 0)
        {
            money = decimal.Parse(dt.Rows[0]["F_SOTIENTHU"].ToString());
        }
        return money;
    }
    #endregion

    #region Lấy nội dung thu
    public static string GetContent(DataTable dt)
    {
        string content = "";
        if (dt.Rows.Count > 0)
        {
            content = dt.Rows[0]["F_DIENGIAI"].ToString();
        }
        return content;
    }
    #endregion

    #region Lấy ngày hết hạn
    public static DateTime GetDateLimit_Current(string F_MALOP)
    {
        DataTable dt = GetLastRowByMaLop(F_MALOP);
        DateTime de = new DateTime();        
        if (dt.Rows.Count > 0)
        {
            de = DateTime.Parse(dt.Rows[0]["F_DENNGAY"].ToString());
        }       
        return de;
    }
    #endregion
    #endregion

    #region Get List By Ma Lop
    public static DataTable GetListByMaLop(string F_MALOP)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MALOP", F_MALOP);
        try
        {
            dt = connect.GetSelectCommand("DOTTHU_GetListByMaLop", para);
        }
        catch
        { 
            
        }
        return dt;
    }
    #endregion

    #region FillComboBox
    public static DataTable FillComboBox(string F_MALOP)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MALOP", F_MALOP);
        try
        {
            dt = connect.GetSelectCommand("DOTTHU_FillComboBox", para);
        }
        catch
        {

        }
        return dt;
    }
    #endregion

    #region Get Last Row By Ma Lop
    public static DataTable GetLastRowByMaLop(string F_MALOP)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MALOP", F_MALOP);
        try
        {
            dt = connect.GetSelectCommand("DOTTHU_GetLastByMaLop", para);
        }
        catch
        { }
        return dt;
    }
    public static DataTable GetLastRowByMaLop_fillcblopchuyentoi(string F_MALOP)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MALOP", F_MALOP);
        try
        {
            dt = connect.GetSelectCommand("DOTTHU_GetLastByMaLop_fillcblopchuyentoi", para);
        }
        catch
        { }
        return dt;
    }
    #endregion

    #region Get By Id
    public static DataTable GetById(string F_MADT)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MADT", F_MADT);
        try
        {
            dt = connect.GetSelectCommand("DOTTHU_GetById", para);
        }
        catch
        { }
        return dt;
    }
    #endregion

    #region Insert
    public static string Insert(string F_MADT, string F_MALOP, int F_STTCAPLOP, DateTime F_TUNGAY, DateTime F_DENNGAY, int F_SOTHANG, decimal F_SOTIENTHU, string F_DIENGIAI, DateTime F_NGAYHETHAN, DateTime F_NGAYTAO)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        object[] values = { F_MADT, F_MALOP, F_STTCAPLOP, F_TUNGAY, F_DENNGAY, F_SOTHANG, F_SOTIENTHU, F_DIENGIAI, F_NGAYHETHAN, F_NGAYTAO };
        string[] parameters = { "@F_MADT", "@F_MALOP", "@F_STTCAPLOP", "@F_TUNGAY", "@F_DENNGAY", "@F_SOTHANG", "@F_SOTIENTHU", "@F_DIENGIAI", "@F_NGAYHETHAN", "@F_NGAYTAO" };
        SqlParameter[] paras = new SqlParameter[parameters.Length];
        for (int i = 0; i < parameters.Length; i++)
        {
            paras[i] = new SqlParameter(parameters[i], values[i]);
        }
        try
        {
            connect.ExecuteQuery("DOTTHU_Insert", paras);
            return "OK";
        }
        catch {
            return "ERR";
        }
    }
    #endregion

    #region Insert Phí Khác
    public void Insert_PTK(string F_MALOP)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MALOP", F_MALOP);
        try
        {
            connect.ExecuteQuery("DOTTHU_Insert_PTK", para);
        }
        catch { }
    }
    #endregion

    #region Delete
    public static string Delete(string F_MADT)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MADT", F_MADT);
        try
        {
            connect.ExecuteQuery("DOTTHU_Delete", para);
            return "OK";
        }
        catch {
            return "ERR";
        }
    }
    #endregion

    #region Update
    public static string Update(string F_MADT, string F_MALOP, int F_STTCAPLOP, DateTime F_TUNGAY, DateTime F_DENNGAY, int F_SOTHANG, decimal F_SOTIENTHU, string F_DIENGIAI, DateTime F_NGAYHETHAN, DateTime F_NGAYTAO, bool F_KHOASO)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        object[] values = { F_MADT, F_MALOP, F_STTCAPLOP, F_TUNGAY, F_DENNGAY, F_SOTHANG, F_SOTIENTHU, F_DIENGIAI, F_NGAYHETHAN, F_NGAYTAO, F_KHOASO };
        string[] parameters = { "@F_MADT", "@F_MALOP", "@F_STTCAPLOP", "@F_TUNGAY", "@F_DENNGAY", "@F_SOTHANG", "@F_SOTIENTHU", "@F_DIENGIAI", "@F_NGAYHETHAN", "@F_NGAYTAO", "@F_KHOASO" };
        SqlParameter[] paras = new SqlParameter[parameters.Length];
        for (int i = 0; i < parameters.Length; i++)
        {
            paras[i] = new SqlParameter(parameters[i], values[i]);
        }
        try
        {
            connect.ExecuteQuery("DOTTHU_Update", paras);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
    #endregion


}